import { BillApi } from '@/api/Bill.api.js'
import { Common } from '@/utils/common.js'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro.replace('/api', '/')

export default {
  name: '',

  data () {
    return {
      isShowTableShebaohuizongModal: false,
      companyName: null,
      companyId: null,
      year: null,
      month: null,
      remark: null,
      billDate: null,
      tableData: [],
      newTableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      year: '',
      month: ''
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },
    /**
     * 分页查询接口
     * @param {Object} obj {pageIndex, pageSize}
     */
    async query () {
      var params = {
        CustomerIds: this.companyId,
        // year: this.year,
        Month: this.billDate
      }
      let res = await BillApi.getMergedSITotal(params)
      console.log('社保汇总res: ', res)
      if (res.status === 200 && res.data.success) {
        this.remark = res.data.message
        var result = res.data.data
        result.map(item => {
          item.billFees.map(c_item => {
            var str = c_item.code + 'Amt'
            item[str] = c_item.amt
          })
          console.log('item: ', item)
        })
        this.newTableData = result
      } else {
        this.newTableData = []
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
      this.loading = false
    },

    ok () {
    },

    cancel () {
    },

    handleExportData () {
    },

    parsingItems (row, item, oneTitle, twoTitle1, twoTitle2, type) {
      var sumTitle = oneTitle + twoTitle1 + type
      console.log('sumTitle: ', sumTitle)
      row[sumTitle] = item[twoTitle1][type]
    },

    // 导出
    async exportSocialInsureTotal () {
      var params = {
        CustomerIds: this.companyId,
        companyName: this.companyName,
        year: this.year,
        month: this.month,
        // Month: this.billDate,
        insures: this.newTableData,
        remark: this.remark
      }
      console.log('导出params: ', params)
      let res = await BillApi.exportSocialInsureTotal(params)
      if (res.status === 200 && res.data.success) {
        console.log('❤ 返回链接: ', baseUrl + res.data.message)
        window.open(baseUrl + res.data.message, '_blank')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    }
  }
}
